package com.smz.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smz.entity.PageEntity;
import com.smz.entity.TStaff;
import com.smz.service.TStaffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.List;

@Api
@RestController
public class TStaffController {
    @Autowired
    private TStaffService tStaffService;

    @ApiOperation("分页查询员工")
    @GetMapping("/tStaffs/page")
    public ResponseEntity<PageEntity<TStaff>> findTStaffsPage(@RequestParam(value = "current",required = false,defaultValue = "1")
                                                                      Integer current){
        PageEntity<TStaff> tStaffsPage = tStaffService.findTStaffsPage(current);
        System.out.println(tStaffsPage);
        return ResponseEntity.ok(tStaffsPage);
    }

    @ApiOperation("查询所有")
    @GetMapping("/tStaffs")
    public ResponseEntity<List<TStaff>> findAllTStaffs(){
        List<TStaff> all =tStaffService.findAllTStaffs() ;
        return ResponseEntity.ok(all);
    }

    @ApiOperation("通过id查询所有")
    @GetMapping("/tStaffs/{id}")
    public ResponseEntity<List<TStaff>> findAllTStaffsById(@PathVariable("id")Integer id){
        List<TStaff> all =tStaffService.findAllTStaffsById(id) ;
        return ResponseEntity.ok(all);
    }

    @ApiOperation("更新员工")
    @PutMapping("/tStaff")
    public ResponseEntity<String>updateStaff(@RequestBody TStaff tStaff){
        tStaffService.saveOrUpdate(tStaff);
        return  ResponseEntity.ok("ok");
    }
    @ApiOperation("增加员工")
    @PostMapping("/tStaff")
    public ResponseEntity<String>addTStaff(@RequestBody TStaff tStaff){
        tStaffService.saveOrUpdate(tStaff);
        return  ResponseEntity.ok("ok");
    }
    @ApiOperation("删除员工")
    @DeleteMapping("/tStaff/{id}")
    public  ResponseEntity<String>deleteTStaff(@PathVariable("id")Integer id){
        tStaffService.removeById(id);
        return ResponseEntity.ok("ok");
    }

    @ApiOperation("模糊查询员工")
    @GetMapping("/tStaffLike/like/{start}/{length}/{name}/{dId}")
    public ResponseEntity<IPage<TStaff>> findTStaffByNameId(@PathVariable("start") Integer start,
                                                            @PathVariable("length") Integer length,
                                                            @PathVariable("name") String name,
                                                            @PathVariable("dId") Integer dId)  {
        IPage<TStaff> tStaffByNameId = tStaffService.findTStaffByNameId(start, length, name, dId);

        return ResponseEntity.ok(tStaffByNameId);
    }
//    @RequestParam(required = false)


    @ApiOperation("通过id查")
    @GetMapping("/tStaff/{id}/{accountStatus}")
    public ResponseEntity<String> findTEnterpriseById(@PathVariable("id")Integer id , @PathVariable("accountStatus") String accountStatus ){
        tStaffService.modifyTStaffById(id,accountStatus);
        return ResponseEntity.ok("ok");
    }




}











